package com.ibm.epss.android;

import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;

public class MqttService extends Service {
    NetworkStateReceiver networkStateReceiver = new NetworkStateReceiver();
    ActivityProfile activityProfile = ActivityProfile.getInstance();

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        this.unregisterReceiver(networkStateReceiver);
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int flag, int startId) {
        super.onStartCommand(intent, flag, startId);

        if (activityProfile.getNotiMgr() == null) {
            Log.d("activityProfile", "setNotiMgr");
            activityProfile.setNotiMgr((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
        }
        if (activityProfile.getIntent() == null) {
            Log.d("activityProfile","setIntent");
            activityProfile.setIntent(intent);
        }
        if (activityProfile.getCtxService() == null) {
            Log.d("activityProfile","setCtxService");
            activityProfile.setCtxService(this);
        }
        Log.d("activityProfile","registerReceiver");
        this.registerReceiver(networkStateReceiver, new IntentFilter());
        return START_STICKY_COMPATIBILITY;
    }

}
